package com.starsea.book.ui.newpage.adapter

import android.content.Context
import android.view.ViewGroup
import com.starsea.book.base.adapter.ItemViewHolder
import com.starsea.book.base.adapter.RecyclerAdapter
import com.starsea.book.databinding.ItemAccountManageListBinding
import com.starsea.book.ui.newpage.entity.AccountEntity
import com.starsea.book.ui.widget.recycler.ItemTouchCallback
import com.starsea.book.utils.visible

class AccountManageAdapter(
    context: Context,
    var onChanged: ((value: AccountEntity) -> Unit)? = null
) :
    RecyclerAdapter<AccountEntity, ItemAccountManageListBinding>(context),
    ItemTouchCallback.Callback {


    override fun getViewBinding(parent: ViewGroup): ItemAccountManageListBinding {
        return ItemAccountManageListBinding.inflate(inflater, parent, false)
    }

    override fun registerListener(holder: ItemViewHolder, binding: ItemAccountManageListBinding) {
        binding.ivEdit.setOnClickListener {
            getItem(holder.layoutPosition)?.let {
                onChanged!!.invoke(it)
            }

        }
    }

    override fun convert(
        holder: ItemViewHolder,
        binding: ItemAccountManageListBinding,
        item: AccountEntity,
        payloads: MutableList<Any>
    ) {
        binding.run {
            tvAccount.text = item.accountNumber
            tvName.text = item.realName
            rtvDefault.visible(item.isDefault == 1)
        }
    }


}